/*
 * @Date: 2019-12-12 11:15:44
 * @LastEditors: 黄栋
 * @LastEditTime: 2020-04-20 10:13:44
 * @FilePath: /cloudAdmin/src/main.js
 */
import Vue from 'vue'
import App from './App.vue'
import router from './router/router.js'
import ElementUI from 'element-ui';
import { isAuth, formatDate, hasRole } from '@/utils'
import httpRequest from '@/utils/httpRequest'
import store from '@/store'
import 'element-ui/lib/theme-chalk/index.css';
import VueI18n from 'vue-i18n'

Vue.use(VueI18n)
//业务组件  
Vue.use(ElementUI);
Vue.prototype.$http = httpRequest
Vue.prototype.hasRole = hasRole
Vue.prototype.isAuth = isAuth //权限验证
Vue.prototype.dateToString = formatDate //时间转换
Vue.config.productionTip = false
// 非生产环境, 适配mockjs模拟数据
// if (window.SITE_CONFIG.hasMock) {
//     require('@/assets/mock')
// }
import '@/assets/style/index.less'
router.beforeEach((to, from, next) => {
    console.log(to)
    if (!sessionStorage.accessToken && to.name !== 'login') {
        next({
            name: 'login',
        })
    } else {
        next()
    }
})
const i18n = new VueI18n({
    locale: 'zh', // 定义默认语言为中文  
    messages: {
        'zh': require('@/assets/languages/zh.json'),
        'en': require('@/assets/languages/en.json')
    }

});

new Vue({
    el: '#app',
    router,
    store,
    i18n,
    render: h => h(App)
})